﻿using System;
using EPiServer.Core;
using TemplateFoundation.PageTypeIcons.IconHandlers;

namespace TemplateFoundation.PageTypeIcons {

    /// <summary>
    /// <para>Attribute used to show an icon when a property has a value.</para>
    /// </summary>
    public class PropertyHasValueIconAttribute : StatusIconAttribute {

        /// <summary>
        /// <para>Initializes a new PropertyHasValueIconAttribute.</para>
        /// </summary>
        /// <param name="imageUrl">The virtual path to the icon to use.</param>
        /// <param name="toolTip">
        /// <para>The tool tip to show on mouseover.</para>
        /// <para>If the value isn't found in the language file, it's considered to be a string constant tool tip.</para>
        /// </param>
        /// <param name="propertyName">The name of the property to check.</param>
        /// <param name="propertyValue">The value to match the property value against.</param>
        /// <param name="excludedPageTypes">The excluded types of pages.</param>
        /// <param name="hideIfShortcut">A value indicating if the icon should be omitted of the LinkType of the page is set to point somewhere else.</param>
        public PropertyHasValueIconAttribute(string imageUrl, string toolTip, string propertyName, object propertyValue, Type[] excludedPageTypes, bool hideIfShortcut)
            : base(imageUrl, toolTip) {
                this.ExcludedPageTypes = excludedPageTypes ?? new Type[0];
                this.Handler = new PropertyHandler(propertyName, propertyValue, false, this.ImageUrl, LanguageManager.Instance.TranslateFallback(this.ToolTip, this.ToolTip), excludedPageTypes, hideIfShortcut);
        }

        /// <summary>
        /// <para>The excluded types of pages.</para>
        /// <para>Matches are only made on pages that aren't in the list of exluded page types.</para>
        /// </summary>
        public Type[] ExcludedPageTypes {
            get;
            private set;
        }
    }
}